import 'package:demo_app_video/commons/router/routes.dart';
import 'package:flutter/material.dart';
import 'package:flutter_adcontent/flutter_adcontent.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class EpisodeDialog extends StatefulWidget {
  Drama drama;
  int currentIndex;
  EpisodeDialog({Key? key,required this.drama,required this.currentIndex}) : super(key: key);

  @override
  State<EpisodeDialog> createState() => _EpisodeDialogState();
}

class _EpisodeDialogState extends State<EpisodeDialog> {
  List dataTotle = [];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    for(int index = 1;index <= widget.drama.total;index++){
      dataTotle.add({
        'title':'第${index}集',
        'index':index
      });
    }
    print(widget.currentIndex);
  }
  

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 360.w,
      height: 430.h,
      padding:
          EdgeInsets.all(16.sp),
      decoration: BoxDecoration(
          color: Color(0xffFFFFFF),
          borderRadius: BorderRadius.only(
              topLeft: Radius.circular(16.sp),
              topRight: Radius.circular(16.sp)),
          gradient: LinearGradient(colors: [
            Color(0xffFFF4E6),
            Color(0xffFFFFFF),
          ], begin: Alignment.topCenter, end: Alignment.bottomCenter)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            height: 35.h,
            child: Row(
              children: [
                Text(
                  '${widget.drama.title}',
                  style: TextStyle(
                      color: Color(0xff333333),
                      fontSize: 16.sp,
                      fontWeight: FontWeight.w500),
                ),
                Container(
                  width: 8.w,
                ),
                Text(
                  '共${widget.drama.total}集',
                  style: TextStyle(color: Color(0xff666666), fontSize: 12.sp),
                ),
                Expanded(child: Container()),
                InkWell(
                  child: Container(
                  width: 12.w,
                  height: 12.w,
                  child: Image.asset('images/close_icon_xuanji.png',fit: BoxFit.fill,),
                ),
                onTap: (){
                  Routes().popNowPage(context);
                },
                )
              ],
            ),
          ),


          Container(
            margin: EdgeInsets.only(
              top: 6.h
            ),
            width: 328.w,
            child: Text('${widget.drama.desc}',style: TextStyle(
              color: Color(0xff999999),
              fontSize: 12.sp
            ),maxLines: 3,overflow: TextOverflow.ellipsis,),
          ),
          Container(height: 16.h,),
          Expanded(child: SingleChildScrollView(
            child: Wrap(
              spacing: 8.w,
              runSpacing: 12.h,
              children: dataTotle.map((item)=>InkWell(
                child: Container(
                width: 76.w,
                height: 32.h,
                decoration: widget.currentIndex != item['index'] ?BoxDecoration(
                  color: Color(0xffFFEAEA),
                  borderRadius: BorderRadius.circular(4.sp)
                ) :BoxDecoration(
                  image: DecorationImage(image: AssetImage('images/jishu_bofang.png'),fit: BoxFit.fill),
                  borderRadius: BorderRadius.circular(4.sp)
                ),
                child: Text('${item['title']}',style: TextStyle(
                  color: widget.currentIndex == item['index'] ?Color(0xffFFFFFF) :Color(0xff333333),
                  fontSize: 12.sp
                ),),
                alignment: Alignment.center,
              ),
              onTap: (){
                Routes().popNowPage(context,data: item['index']);
              },
              )).toList(),
            ),
          ))
        ],
      ),
    );
  }
}
